package cc.chinagps.gateway.unit.eg.util;

import cc.chinagps.gateway.buff.GBossDataBuff;
import cc.chinagps.gateway.buff.GBossDataBuff.GpsBaseInfo;
import cc.chinagps.gateway.buff.GBossDataBuff.GpsInfo;
import cc.chinagps.gateway.unit.UnitServer;
import cc.chinagps.gateway.unit.UnitSocketSession;
import cc.chinagps.gateway.unit.eg.pkg.EGPackage;
import cc.chinagps.gateway.unit.eg.upload.bean.EGAlarmInfo;
import cc.chinagps.gateway.unit.eg.upload.bean.EGRealTimeInfo;
import cc.chinagps.gateway.unit.eg.upload.bean.JMCDriving;
import cc.chinagps.gateway.unit.eg.upload.bean.JMCFault;

public class EGUploadUtil {
    public static void msgAck(UnitSocketSession session, EGPackage pkg, byte[] responseData)
            throws Exception {
        // TODO Auto-generated method stub
        EGPackage rpkg = new EGPackage();
        rpkg.setHead(pkg.getHead());
        if (responseData != null) {
            rpkg.getHead().setBodyLen((short) (responseData.length));
        }
        rpkg.setData(responseData);
        session.sendData(rpkg.encode());
    }

    public static void handleRealTimeInfo(EGPackage pkg, UnitServer server, UnitSocketSession session, EGRealTimeInfo egRealTimeInfo) {
        String callLetter = session.getUnitInfo().getCallLetter();

        GpsInfo gpsInfo = EGProtobufUtil.transformGPSInfo(callLetter, pkg, egRealTimeInfo);
        GpsBaseInfo gpsBase = gpsInfo.getBaseInfo();

        server.getExportMQ().addGPS(gpsInfo);
        server.getExportHBase().addGPS(callLetter, gpsBase, pkg.getSource());
    }

    public static void handleAlarmInfo(EGPackage pkg, UnitServer server, UnitSocketSession session, EGAlarmInfo egAlarmInfo) {
        String callLetter = session.getUnitInfo().getCallLetter();
        GBossDataBuff.EGAlarm alarm = EGProtobufUtil.transformEGAlarmInfo(callLetter, pkg, egAlarmInfo);
        server.getExportMQ().addEgAlarm(alarm);
    }

    public static void handleJMCInfo(EGPackage pkg, UnitServer server, UnitSocketSession session, JMCDriving jmcDriving, JMCFault jmcFault) {
        String callLetter = session.getUnitInfo().getCallLetter();
        GBossDataBuff.EGJMCInfo jmcInfo = EGProtobufUtil.transformEGJMCInfo(callLetter, pkg, jmcDriving, jmcFault);
        server.getExportMQ().addEgJMCInfo(jmcInfo);
    }


}